package me.zhengjie.modules.sync.pull.v20;

import com.qiaofang.applet.common.constant.SyncTypeEnum;
import com.qiaofang.applet.service.property.domain.PropertyVideo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static me.zhengjie.modules.quartz.service.constants.SyncConstants.V20_PRO_VIDO_API;

/**
 * @author QF2019
 */
@Service
@Slf4j
public class V20PropertyVidoSync extends MarketingPullBase{

    @Autowired
    private MongoTemplate mongoTemplate;

    public V20PropertyVidoSync(){
        super.pageSize = 30;
    }

    @Override
    protected String getApiUrl() {
        return V20_PRO_VIDO_API;
    }

    @Override
    protected String dataType() {
        return SyncTypeEnum.PRO_VIDEO.getSyncType();
    }

    @Override
    public String getResourceType() {
        return "PROPERTY_VIDEO";
    }

    @Override
    public void removeBusinessData(List<String> uuids) {
        if (CollectionUtils.isEmpty(uuids)){
            return;
        }
        Criteria criteria = Criteria.where("videoUuid").in(uuids);
        Query query = new Query();
        query.addCriteria(criteria);
        mongoTemplate.remove(query, PropertyVideo.class);
    }
}
